import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'


import { Tabbar, TabbarItem } from 'vant';
import { Tab, Tabs } from 'vant';
import { Swipe, SwipeItem } from 'vant';
import { Lazyload } from 'vant';
import { NavBar } from 'vant';
import { Field } from 'vant';
import { Uploader } from 'vant';
import { Empty } from 'vant';
import { Popup } from 'vant';
import { Loading } from 'vant';

Vue.use(Loading);

Vue.use(Popup);

Vue.use(Empty);
Vue.use(Uploader);
Vue.use(Field);
Vue.use(NavBar);
Vue.use(Lazyload);


Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Tab);
Vue.use(Tabs);

Vue.use(Tabbar);
Vue.use(TabbarItem);
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login,
    alias: '/login'
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
  },
  {
    path: '/register',
    name: 'register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Register.vue'),

  },
  {
    path: '/rankingList',
    name: 'rankingList',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/RankingList.vue'),

  },
  {
    path: '/search',
    name: 'search',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Search.vue'),

  },
  {
    path: '/withdraw',
    name: 'withdraw',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Withdraw.vue'),

  },
  {
    path: '/my',
    name: 'my',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/My.vue'),
    beforeEnter(to,from,next) {
      let token = localStorage.getItem('token')
      // console.log(token);
      // console.log(to);
      // console.log(from);
      if(token != null) {
          next()
      }else {
        next({name:'login'})
        setTimeout('console.clear()', 300)
        return
      }
    }
  },
  {
    path: '/release',
    name: 'release',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Release.vue'),
    beforeEnter(to,from,next) {
      let token = localStorage.getItem('token')
      // console.log(token);
      // console.log(to);
      // console.log(from);
      if(from.path == '/home' || from.path == '/my') {
        if(token) {
          next()
        }else {
          next({name:'login'})
          setTimeout('console.clear()', 300)
          return
        }
      }
    }
  },
  {
    path: '/revise',
    name: 'revise',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Revise.vue'),

  },
  {
    path: '/taskDetail',
    name: 'taskDetail',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/TaskDetail.vue'),

  },
  {
    path: '/taskDetail2',
    name: 'taskDetail2',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/TaskDetail2.vue'),

  },
  {
    path: '/myTask',
    name: 'myTask',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/MyTask.vue'),

  },
]

const router = new VueRouter({
  routes
})

export default router
